#ifndef _contest_divisors_h_
#define _contest_divisors_h_

#include<stdint.h>
#include<assert.h>

namespace contest
{
/**
 * Number of divisors of n.
 * @param n: The number to calculate. 
 * @return: The number of divisors. 
 **/
uint32_t divisors(uint32_t n)
{
    uint32_t result = 1;
    for (int i=2; i*i<=n; ++i)
        if (n % i == 0)
        {
            uint32_t count;
            for (count=1; n % i == 0; ++count)
                n /= i;
            result *= count;
        }
    if (n > 1)
        result *= 2;
    return result;
}

void test_sigma()
{
    assert(divisors(1) == 1);
    assert(divisors(2) == 2);
    assert(divisors(4) == 3);
    assert(divisors(30) == 8);
}
}

#endif
